package com.niiwoo.civet.scheduler.trigger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.niiwoo.civet.trade.service.invest.AutoInvestDubboService;
import com.niiwoo.civet.trade.service.invest.InvestJobDubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by zhangwanli on 2017/11/22.
 */
@Component
public class InvestJobTrigger {
    private static final Logger logger = LoggerFactory.getLogger(InvestJobTrigger.class);

    @Reference(version = "1.0.0")
    private InvestJobDubboService investJobDubboService;

    @Reference(version = "1.0.0")
    private AutoInvestDubboService autoInvestDubboService;

    @Scheduled(cron = "${invest.revert-auto-investor}")
    public void revertAutoInvestorQueue() {
        logger.info("调度自动投资人恢复到队列");
        RpcContext.getContext().asyncCall(() -> investJobDubboService.revertAutoInvestorQueue());
    }

    @Scheduled(fixedRate = 12 * 60 * 60 * 1000L)
    public void reloadAutoInvestorQueue() {
        logger.info("调度重新加载自动投资人队列");
        RpcContext.getContext().asyncCall(() -> autoInvestDubboService.reloadAutoInvestorQueue());
    }

}
